package com.hzdl.apple.service;

import java.sql.Connection;

import com.hzdl.apple.bean.User;
import com.hzdl.apple.dao.UserDao;
import com.hzdl.apple.dao.imp.UserDaoImp;

public class UserService {
	private UserDao dao;
	
	public UserService(){
		dao = new UserDaoImp();
	}
	
	//登录
		public User login(String id, String psw) {
			return dao.getUser(id, psw);
		}
	//注册
		public String register(String uname, String uid, String psw,String address,String uPhoneNum) {
			User user = new User(uname, uid, psw, address, uPhoneNum);
			if (dao.isExist(uid)) {
				return "该用户已存在！";
			} else {
				boolean flag = dao.addUser(user);
				if (flag) {
					return "注册成功！";
				} else {
					return "注册失败！";
				}
			}
		}
	//修改密码
		public void changePsw(User user,String newPassword){
			dao.changePassword(user, newPassword);
		}
	//留言
		public void leaveMessage(String uName,String uMessage ){
			
			dao.UpdateUser(uName,uMessage);
		}
	//用户信息
		public User  userInfo(String UName){
			return dao.showUser(UName);
			
		}
		public User findPsw(String uname, String uphone) {
			return dao.getUser(uname, uphone);
		}
}
